package nl.scalasim
package actors
package traits

import nl.scalasim.util.Accumulator


/**
 * A producing actor produces goods at a specified speed. Each time
 * the ProducingActor receives a 'Process' message, it replies with
 * a 'Produced(goods, n)' message, indicating the produced goods and
 * the amount of goods produced. 
 *
 * @author Yigal Duppen
 * @since Oct 4, 2010
 */

trait ProducingActor extends SimulationActor {

  val goods: Goods

  val speed: Int

  private var production = new Accumulator(speed)

  def handleProcess: PartialFunction[Any, Unit] = {
    case Process => {
      production = production.accumulate()
      reply(Produced(goods, production.overflow))
    }
  }

  callbacks :+= handleProcess
}